﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manageweb_TiXian_TXManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["MasterID"]==null)
        {
            Response.Redirect("../Default.aspx");
        }

        if (!Page.IsPostBack)
        {
            BindTXData();
        }
    }

    protected void BindTXData()
    {
        //SQLExpressDAL.StockTableAdapters.TiXianTableAdapter adp = new SQLExpressDAL.StockTableAdapters.TiXianTableAdapter();
        //this.GV_TXList.DataSource = adp.GetAllTXBill();
        //this.GV_TXList.DataBind();
        SQLExpressDAL.DealRecord obj = new SQLExpressDAL.DealRecord();
        this.GV_TXList.DataSource = obj.GetTiXianRecord(this.txtUserAccount.Text.Trim(), this.txtBeginDate.Text.Trim(), this.txtEndDate.Text.Trim());
        this.GV_TXList.DataBind();
    }
    protected void lbtnApprove_Click(object sender, EventArgs e)
    {
        Control lbtnControl = (Control)sender;
        GridViewRow gr = (GridViewRow)lbtnControl.NamingContainer;

        Int32 txID = Convert.ToInt32( this.GV_TXList.DataKeys[gr.RowIndex][0]);
        String userID = gr.Cells[0].Text;
        String userName = gr.Cells[1].Text;
        String cMoney = ((Label)gr.Cells[2].FindControl("lblCMoney")).Text;

        SQLExpressDAL.TiXianTableAdapters.TiXianTableAdapter adp = new SQLExpressDAL.TiXianTableAdapters.TiXianTableAdapter();
        SQLExpressDAL.TiXian.TiXianRow dr = (SQLExpressDAL.TiXian.TiXianRow)adp.GetSingleTiXianRecord(txID).Rows[0];
        
        this.hidTXID.Value = dr.ID.ToString();
        this.txtMemID.Text = dr.UserID;
        this.lblUserName.Text = dr.UserName;
        this.DDLBank.SelectedValue = dr.BankName;
        this.txtBackCode.Text = dr.UserBankCode;
        this.txtMaoMoney.Text = dr.MaoMoney.ToString();
        this.txtFei.Text = dr.ShouXuMoney.ToString();
        this.ddl_area.SelectedValue = dr.area;
        this.txtBankfen.Text= dr.BankFenName;
        this.txtUserBankName.Text = dr.UserBankName;
        this.txtJingE.Text = dr.CMoney.ToString();
        this.txtMemo.Text = dr.Cmemo;

        this.trShenHe.Visible = true;
        this.TABLE_Query.Visible = false;

    }

    protected void btnPass_Click(object sender, EventArgs e)
    {
        try
        { 
            SQLExpressDAL.DealRecord obj = new SQLExpressDAL.DealRecord();
            int flag = obj.ApproveTiXianShengQing(this.txtMemID.Text, Convert.ToDecimal(this.txtMaoMoney.Text), Convert.ToInt32(this.hidTXID.Value), 1, Session["MasterName"].ToString());


            if (flag > 0)
            {  
                this.msg.InnerText = "审核成功!";
            }
            else
            {
                this.msg.InnerText = "审核失败!";
            }
        }
        catch (Exception ex)
        {
            this.msg.InnerText = ex.Message;
        }
        finally
        {
            this.trShenHe.Visible = false;
            ClearTxt();
            BindTXData();
            this.trShenHe.Visible = false;
            this.TABLE_Query.Visible = true;
        }

    }

    protected void ClearTxt()
    {
       
    }
    protected void btnReject_Click(object sender, EventArgs e)
    {
        try
        {

            SQLExpressDAL.StockTableAdapters.TiXianTableAdapter adp = new SQLExpressDAL.StockTableAdapters.TiXianTableAdapter();
            int flag = adp.UpdateTXState(Session["MasterName"].ToString(), DateTime.Now, 4, Convert.ToInt32(this.hidTXID.Value));

            if (flag > 0)
            {
                this.msg.InnerText = "驳回成功!";
            }
            else
            {
                this.msg.InnerText = "驳回失败!";
            }
        }
        catch (Exception ex)
        {
            this.msg.InnerText = ex.Message;
        }
        finally
        {
            this.trShenHe.Visible = false;
            ClearTxt();
            BindTXData();
            this.trShenHe.Visible = false;
            this.TABLE_Query.Visible = true;
        }
    }
    protected void Btn_Submit_Click(object sender, EventArgs e)
    {
        BindTXData();
    }


    protected void GV_TXList_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GV_TXList.PageIndex = e.NewPageIndex;
        BindTXData();
    }
    protected void btnShowQuery_Click(object sender, EventArgs e)
    {
        this.trShenHe.Visible = false;
        this.TABLE_Query.Visible = true;
    }
}
